convsLastMsgCount = [];

function update(isBlur) {
    if (is_img.className == 'is_img c_ic_redframe') { /* c_ic_greenframe c_ic_orangeframe c_ic_blueframe */
        return;
    }
    var convs = wim_cw.getElementsByClassName('wlxim_conv_area');
    for (var i = 0; i < convs.length; i++) {
        var conv_id = parseInt(convs[i].firstChild.firstChild.id.substr(28));
        if (conv_id >= convsLastMsgCount.length) {
            convsLastMsgCount.push(0);
        }
        var says = convs[i].getElementsByClassName('wlxim_msgwrap');
        if (says.length != convsLastMsgCount[conv_id]) {
            convsLastMsgCount[conv_id] = says.length;
            if (isBlur) {
                port.postMessage({
                    name: convs[i].firstChild.firstChild.childNodes[1].firstChild.firstChild.innerHTML,
                    text: says[says.length - 1].firstChild.innerHTML,
                    img: convs[i].firstChild.firstChild.firstChild.firstChild.childNodes[1].firstChild.src
                });
            }
        }
    }
}
document.onreadystatechange = function() {
    if (document.readyState == 'complete') {
        wim_r.removeChild(wim_ins);
        is_img = ic1_frame.firstChild;
        port = chrome.extension.connect({
            name: 'WebIM'
        });
        onblur = function() {
            update(false);
            intervalID = setInterval('update(true)', 1000);
        };
        onfocus = function() {
            clearInterval(intervalID);
        };
    }
}